package cn.itcast.mapper;

import cn.itcast.dto.OrdersDto;
import cn.itcast.entity.Orders;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface IOrderMapper {
    @Insert("insert into orders values(#{id},#{number},#{status},#{userId}" +
            ",#{addressBookId},#{orderTime},#{checkoutTime},#{payMethod}" +
            ",#{amount},#{remark},#{phone},#{address},#{userName},#{consignee})")
    void save(Orders orders);

    List<Orders> page(String number, String beginTime, String endTime);

     @Select("SELECT o.status,o.order_time,od.name,od.number,od.name,o.amount FROM orders o LEFT JOIN order_detail od ON  o.id =od.order_id WHERE user_id =#{userId}")
     List<OrdersDto> userPage(Long userId);

     @Select("SELECT SUM(od.number) sumNUM FROM orders o LEFT JOIN order_detail od ON  o.id =od.order_id WHERE user_id =#{userId}")
     Integer sumNum(Long userId);
}
